package com.ihisomp.controller;

import com.ihisomp.base.Result;
import com.ihisomp.dto.SysAntibioticDto;
import com.ihisomp.service.ISysAntibioticService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 标题: SysAntibioticController.java
 * 业务描述: 抗生素等级字典 前端控制器
 * 作者: zy
 * 日期: 2021/9/13
 * 版本: V1.0
 */
@RestController
@Api(value = "抗生素等级信息", tags = "抗生素等级信息")
@RequestMapping("/sysAntibiotic")
public class SysAntibioticController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ISysAntibioticService sysAntibioticService;

    /**
     * 新增数据
     *
     * @param sysAntibioticDto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增数据")
    @ApiImplicitParam(name = "sysAntibioticDto", value = "抗生素等级数据类", required = true)
    public Result add(@RequestBody SysAntibioticDto sysAntibioticDto) {
        logger.info("新增数据：sysAntibioticDto={}", sysAntibioticDto);
        Result result = sysAntibioticService.add(sysAntibioticDto);
        return result;
    }

    /**
     * 删除数据
     *
     * @param antibioticKey
     * @return
     */
    @GetMapping("/delete/{antibioticKey}")
    @ApiOperation("删除数据")
    @ApiImplicitParam(name = "antibioticKey", value = "抗生素等级主键", required = true)
    public Result delete(@PathVariable("antibioticKey") String antibioticKey) {
        logger.info("删除数据：antibioticKey={}", antibioticKey);
        Result result = sysAntibioticService.delete(antibioticKey);
        return result;
    }

    /**
     * 更新数据
     *
     * @param antibioticKey
     * @param sysAntibioticDto
     * @return
     */
    @PostMapping("/update/{antibioticKey}")
    @ApiOperation("更新数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "antibioticKey", value = "抗生素等级主键", required = true),
            @ApiImplicitParam(name = "sysAntibioticDto", value = "抗生素等级数据类", required = true)})
    public Result update(@PathVariable("antibioticKey") String antibioticKey, @RequestBody SysAntibioticDto sysAntibioticDto) {
        logger.info("更新数据：antibioticKey={}， sysAntibioticDto={}", antibioticKey, sysAntibioticDto);
        Result result = sysAntibioticService.update(antibioticKey, sysAntibioticDto);
        return result;
    }

    /**
     * 查询数据
     *
     * @param antibioticKey
     * @return
     */
    @GetMapping("/get/{antibioticKey}")
    @ApiOperation("查询数据")
    @ApiImplicitParam(name = "antibioticKey", value = "抗生素等级主键", required = true)
    public Result get(@PathVariable("antibioticKey") String antibioticKey) {
        logger.info("查询数据：antibioticKey={}", antibioticKey);
        Result result = sysAntibioticService.get(antibioticKey);
        return result;
    }

    /**
     * 分页查询
     *
     * @param page
     * @param size
     * @param sysAntibioticDto
     * @return
     */
    @PostMapping("/search/{page}/{size}")
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true),
            @ApiImplicitParam(name = "size", value = "每页条数", required = true),
            @ApiImplicitParam(name = "sysAntibioticDto", value = "抗生素等级数据类", required = true)})
    public Result search(@PathVariable("page") long page,
                         @PathVariable("size") long size,
                         @RequestBody(required = false) SysAntibioticDto sysAntibioticDto) {
        logger.info("分页查询：page={}， size={}, sysAntibioticDto={}", page, page, sysAntibioticDto);
        Result result = sysAntibioticService.search(page, size, sysAntibioticDto);
        return result;
    }

}
